class ToolTypesController < ApplicationController
  before_filter :authorize_for_admin
  layout 'base.html'
  
  def index
    @tool_types = ToolType.all
    @seo_title = "麦吐司网-吐司分类管理"
    @seo_keywords = @seo_title
    @seo_description = @seo_title
  end
  
  def new 
    @tool_type = ToolType.new
  end
  
  def create
    @tool_type = ToolType.new params[:tool_type]
    @tool_type.save ? redirect_to(:action => :index) : render(:new)
  end
  
  def edit
    @tool_type = ToolType.find(params[:id])
  end
  
  def update
    @tool_type = ToolType.find(params[:id])
    @tool_type.update_attributes(params[:tool_type]) ? redirect_to(:action => :index) : render(:edit)
  end
  
  def destroy
    @tool_type = ToolType.find(params[:id])
    if @tool_type.tools.many?
      render :text => '请先删除从属的吐司', :status => 500
    else
      @tool_type.destroy
      render :text => '成功删除', :status => 200
    end
  end 
end
